package design.pattern.Lu09CommandPattern;

/**
 * @program JavaBase
 * @description: 命令模式
 * @author: zhanglu
 * @create: 2020-03-30 09:28:00
 */
public class Lu09CommandPattern01 {

    public static void main(String[] args) {

        Invoker01 invoker01 = new Invoker01(new AddRequirementCommand());
        invoker01.action();


    }

}

interface Group{

    void find();

    void add();

    void delete();

    void update();

    void plan();

}

class RequirementGroup implements Group{

    @Override
    public void find() {
        System.out.println("找到需求组");
    }

    @Override
    public void add() {
        System.out.println("增加一个需求");
    }

    @Override
    public void delete() {
        System.out.println("删除一个需求");
    }

    @Override
    public void update() {
        System.out.println("修改一个需求");
    }

    @Override
    public void plan() {
        System.out.println("需求变更计划");
    }
}

class PageGroup implements Group{

    @Override
    public void find() {
        System.out.println("找到页面组");
    }

    @Override
    public void add() {
        System.out.println("增加一个页面");
    }

    @Override
    public void delete() {
        System.out.println("删除一个页面");
    }

    @Override
    public void update() {
        System.out.println("修改一个页面");
    }

    @Override
    public void plan() {
        System.out.println("页面变更计划");
    }
}

class CodeGroup implements Group{

    @Override
    public void find() {
        System.out.println("找到代码组");
    }

    @Override
    public void add() {
        System.out.println("增加一个功能");
    }

    @Override
    public void delete() {
        System.out.println("删除一个功能");
    }

    @Override
    public void update() {
        System.out.println("修改一个功能");
    }

    @Override
    public void plan() {
        System.out.println("功能变更计划");
    }
}

abstract class Command01{

    protected RequirementGroup requirementGroup = new RequirementGroup();
    protected PageGroup pageGroup = new PageGroup();
    protected CodeGroup codeGroup = new CodeGroup();

    abstract void execute();

}

class AddRequirementCommand extends Command01{

    @Override
    public void execute() {
        super.requirementGroup.find();
        super.requirementGroup.add();
        super.requirementGroup.plan();
    }

}

class DeletePageCommand extends Command01{

    @Override
    void execute() {
        super.pageGroup.find();
        super.pageGroup.add();
        super.pageGroup.plan();
    }
}

class Invoker01{

    private Command01 command01;

    public Invoker01(Command01 command01){
        this.command01 = command01;
    }

    public void action(){
        this.command01.execute();
    }

}








